/** 
 * All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
 * 
 *PmResourceArchivesController
 * 资源档案
 * 
 * 修改纪录
 * 2020-05-07 版本：1.0 shenyouyi 创建。
 * @version 版本：1.0
 * @author 作者：shenyouyi
 * 创建日期：2020-05-07
 */

package com.topscomm.pm.controller;

import java.util.List;
import java.util.Map;

import com.topscomm.cbo.pojo.CboOrgEntity;
import com.topscomm.cbo.service.ICboOrgService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.pm.controller.auto.PmResourceArchivesControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

import javax.annotation.Resource;

/**
 * @author: shenyouyi
 * @date: 2020-05-07
 * @description:资源档案Controller
 * @modify:
 */
@RestController
@RequestMapping("pm/resourceArchives")
public class PmResourceArchivesController extends PmResourceArchivesControllerAuto implements IPmResourceArchivesController {

	@Resource(name="cboOrgService")
	private ICboOrgService cboOrgService;

	/**
	 * @author: shenyouyi
	 * @date: 2020-05-07
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-05-07
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * 根据部门ID查询组织信息
	 * @param paraMap
	 * @return
	 */
	@GetMapping(value = "/queryOrgByDeptId")
	public ResponseResult<Object> queryOrgByDeptId(@RequestParam Map<String, Object> paraMap) {
		// 单独的业务使用单独的类
		String deptId = (String)paraMap.get("deptId");
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle("id in (select orgid from cbodept where id = {0})", deptId);
		List<CboOrgEntity> cboOrgEntityList = cboOrgService.queryByWhere(sql.toString());
		CboOrgEntity resultEntity = cboOrgEntityList.size()>0?cboOrgEntityList.get(0): (new CboOrgEntity());
		return ResponseResult.ok(resultEntity);
	}

}

